package com.xc.h05.controller.renMengBinController;

import com.github.pagehelper.PageInfo;
import com.xc.h05.service.renMengBinService.CoursetypeRMBService;
import com.xc.h05.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/coursetypeRMB")
public class CoursetypeController {
    @Autowired
    private CoursetypeRMBService coursetypeRMBService;

    //分页查询所有
    @GetMapping("/getAll")
    public R getAll(
            @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize,
            com.xc.h05.entity.Coursetype coursetype
    ) {
        PageInfo<com.xc.h05.entity.Coursetype> pageInfo = coursetypeRMBService.findAll(pageNum, pageSize,coursetype);
        return R.ok(pageInfo);
    }

    //根据id删除
    @DeleteMapping("/{id}")
    public R deleteById(@PathVariable("id") Long id) {
        int i = coursetypeRMBService.deleteById(id);
        if (i == 0) {
            return R.fail("删除失败");
        }else return R.ok("删除成功");

    }
    //添加
    @PostMapping()
    public R add(@RequestBody com.xc.h05.entity.Coursetype coursetype) {
        int i = coursetypeRMBService.add(coursetype);
        if (i == 0) {
            return R.fail("添加失败");
        }else return R.ok("添加成功");
    }
    //修改
    @PutMapping()
    public R update(@RequestBody com.xc.h05.entity.Coursetype coursetype) {
        int i = coursetypeRMBService.update(coursetype);
        if (i == 0) {
            return R.fail("修改失败");
        }else return R.ok("修改成功");
    }
    //根据id批量删除
    @DeleteMapping("/deleteByIds")
    public R deleteByIds(@RequestBody java.util.List<Long> ids) {
        int i = coursetypeRMBService.deleteByIds(ids);
        if (i >= 0) {
            return R.fail("批量删除成功");
        }else return R.ok("批量删除失败");
    }
}
